package com.lidastudio.dbdatamock.thread;

import java.util.concurrent.BrokenBarrierException;
import java.util.concurrent.CyclicBarrier;

import com.lidastudio.dbdatamock.service.IDatabaseService;
import com.zaxxer.hikari.HikariDataSource;

public class MockThread extends Thread{
	private IDatabaseService databaseService;
	private HikariDataSource ds;
	private String databaseName; 
	private String tableName;
	private Long mockCount;
	private Integer batchSize;
	private CyclicBarrier cb;
	
	public MockThread(IDatabaseService databaseService, HikariDataSource ds, String databaseName, String tableName,
			Long mockCount, Integer batchSize, CyclicBarrier cb) {
		super();
		this.databaseService = databaseService;
		this.ds = ds;
		this.databaseName = databaseName;
		this.tableName = tableName;
		this.mockCount = mockCount;
		this.batchSize = batchSize;
		this.cb = cb;
	}

	@Override
	public void run() {
		
		
		try {
			databaseService.mock(ds, databaseName, tableName, mockCount, batchSize);
			
			System.out.println(Thread.currentThread().getName() + " - insert done, await...");
			cb.await();
			System.out.println(Thread.currentThread().getName() + " - done");
		} catch (InterruptedException e) {
			e.printStackTrace();
		} catch (BrokenBarrierException e) {
			e.printStackTrace();
		} catch (Exception e) {
			e.printStackTrace();
		}
		
	}

}
